package com.example.schoolenterprisealliance.activity;
//互联网+
import androidx.appcompat.app.AppCompatActivity;
import androidx.recyclerview.widget.GridLayoutManager;
import androidx.recyclerview.widget.LinearLayoutManager;
import androidx.recyclerview.widget.RecyclerView;

import android.content.Intent;
import android.os.Bundle;
import android.os.StrictMode;
import android.util.Log;
import android.view.View;
import android.widget.EditText;
import android.widget.ImageView;
import android.widget.TextView;

import com.chad.library.adapter.base.BaseQuickAdapter;
import com.example.schoolenterprisealliance.R;
import com.example.schoolenterprisealliance.adapter.InternetAdapter1;
import com.example.schoolenterprisealliance.adapter.InternetAdapter2;
import com.example.schoolenterprisealliance.adapter.NavigationAdapter;
import com.example.schoolenterprisealliance.bean.Information;
import com.example.schoolenterprisealliance.bean.Navigation;
import com.example.schoolenterprisealliance.method.Skip;

import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.Date;
import java.util.List;

public class InternetActivity extends AppCompatActivity {

    private RecyclerView recyclerView1;
    private RecyclerView recyclerView2;
    private InternetAdapter1 internetAdapter1;
    private InternetAdapter2 internetAdapter2;
    private RecyclerView rv_navigation;
    private NavigationAdapter navigationAdapter;
    private Skip skip;//跳转
    private Intent intent;
    private EditText et_search;
    private ImageView iv_search;
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_internet);

        recyclerView1=findViewById(R.id.re_dynamic1);
        recyclerView2=findViewById(R.id.re_dynamic2);
        rv_navigation=findViewById(R.id.rv_navigation);
        et_search = findViewById(R.id.et_search);
        iv_search = findViewById(R.id.iv_search);
        //一个是前一个activity的退出，另一个activity的进入。
        overridePendingTransition(R.animator.into_right, R.animator.out_left);
        if (android.os.Build.VERSION.SDK_INT > 9) {
            StrictMode.ThreadPolicy policy = new StrictMode.ThreadPolicy.Builder().permitAll().build();
            StrictMode.setThreadPolicy(policy);
        }

        if (android.os.Build.VERSION.SDK_INT > 9) {
            StrictMode.ThreadPolicy policy = new StrictMode.ThreadPolicy.Builder().permitAll().build();
            StrictMode.setThreadPolicy(policy);
        }
        LinearLayoutManager linearLayoutManager1=new GridLayoutManager(this,2);
        linearLayoutManager1.setOrientation(LinearLayoutManager.VERTICAL);
        recyclerView1.setLayoutManager(linearLayoutManager1);
        internetAdapter1=new InternetAdapter1(R.layout.item_policy,initData());
        recyclerView1.setAdapter(internetAdapter1);

        LinearLayoutManager linearLayoutManager2 =new GridLayoutManager(this,5);
        linearLayoutManager2.setOrientation(LinearLayoutManager.VERTICAL);
        recyclerView2.setLayoutManager(linearLayoutManager2);
        internetAdapter2=new InternetAdapter2(R.layout.item_dynamic2,initData());
        recyclerView2.setAdapter(internetAdapter2);



        LinearLayoutManager linearLayoutManager3 = new GridLayoutManager(this, 5);
        linearLayoutManager3.setOrientation(LinearLayoutManager.VERTICAL);
        rv_navigation.setLayoutManager(linearLayoutManager3);
        navigationAdapter=new NavigationAdapter(R.layout.item_navigation, addNavigation());
        rv_navigation.setAdapter(navigationAdapter);
        navigationListener();
        searchIntent();
        ivImageIntent();
    }
    public List<Information> initData(){
        List<Information> list=new ArrayList<>();
        Date date;
        Information information;
        for (int i=0;i<10;i++){
            information=new Information();
            date=new Date();
            SimpleDateFormat simpleDateFormat=new SimpleDateFormat("yyyy-MM-dd");
//            information.setTime(simpleDateFormat.format(date));
//            myDrawable=new MyDrawable();
//            information.setImg_url(myDrawable.drawable("http://i1.sinaimg.cn/ent/d/2008-06-04/U105P28T3D2048907F326DT20080604225106.jpg"));
//            information.setContext("概要"+i);
//            list.add(information);
        }
        return list;
    }
    //添加导航栏数据
    private List<Navigation> addNavigation() {
        List<Navigation> data = new ArrayList<>();
        Navigation navigation;
        for (int i=0;i<5;i++){
            navigation=new Navigation();
            if (i==0){
                navigation.setId(i);
                navigation.setNavigetion("首页");
                data.add(navigation);
                continue;
            }else if (i==1){
                navigation.setId(i);
                navigation.setNavigetion("联盟介绍");
                data.add(navigation);
                continue;
            }else if (i==2){
                navigation.setId(i);
                navigation.setNavigetion("最新动态");
                data.add(navigation);
                continue;
            }else if (i==3){
                navigation.setId(i);
                navigation.setNavigetion("最新政策");
                data.add(navigation);
                continue;
            }else {
                navigation.setId(i);
                navigation.setNavigetion("互联网+");
                data.add(navigation);
                continue;
            }
        }
        return data;
    }
    //导航栏监听
    private void navigationListener(){
        navigationAdapter.setOnItemClickListener(new BaseQuickAdapter.OnItemClickListener() {
            @Override
            public void onItemClick(BaseQuickAdapter adapter, View view, int position) {
                TextView tv=view.findViewById(R.id.tv_navigation);
                String s=tv.getText().toString();
                if (s.equals("互联网+")){

                }else {
                    skip=new Skip(InternetActivity.this,s);
                    intent=skip.intent();
                    startActivity(intent);
                }

                Log.e("navagationListener",tv.getText().toString());
            }
        });
    }
    //点击搜索框跳转
    private void searchIntent(){
        et_search.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                Intent intent=new Intent(InternetActivity.this, SearchHotActivity.class);
                startActivity(intent);
            }
        });
    }
    // 点击搜索图片跳转
    private void ivImageIntent(){
        iv_search.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                Intent intent=new Intent(InternetActivity.this,SearchHotActivity.class);
                startActivity(intent);
            }
        });
    }
}
